<template>
	<view class="search-wrapper">
		<view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input v-model="keyword" @input="inputKey" :adjust-position="false" type="text"
					placeholder="请输入2个及以上关键字查询" confirm-type="search" />
			</view>
			<view class="action" @click="handleSearch">
				<button class="cu-btn bg-green shadow-blur round">搜索</button>
			</view>
		</view>

		<view class="search-list font-35">
			<view class="list-item flex-sb" v-for="(item,index) in listData" :key="index" @click="selectData(item)">
				<view class="text-blue">{{ item.VNAME || item.RealName }}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex";
	import api from "../../common/api.js";
	import util from "../../common/util.js";
	let _self, searchUrl, urlParams, types, queryJson;
	export default {
		computed: mapState(["userInfo"]),
		data() {
			return {
				type: "",
				title: "",
				keyword: "",
				listData: [],
				i: "",
				organizeId: ""
			};
		},

		onLoad: function(params) {
			_self = this;
			let title = "查询";
			types = params.t;
			_self.type = types;
			_self.organizeId = params.organizeId || params.PK_GROUP || params.PK_ORG || _self.userInfo.ORGANIZEID;
			_self.i = params.i;
			queryJson = params.queryjson;
			// console.log(JSON.stringify(_self.userInfo));
			console.log(params);
			switch (params.t) {
				case "GROUP":
					_self.title = "查询集团";
					break;
				case "BA_ORGANIZE":
					_self.title = "查询组织";
					break;
				case "BA_DEPARTMENT":
					_self.title = "查询部门";
					// _self.organizeId = params.PK_ORG
					break;
				case "BA_USER":
					_self.title = "查询人员";
					break;
				case "BD_SUPPLIER":
					_self.title = "查询供应商";
					break;
				case "BD_STORE":
					_self.title = "查询仓库";
					break;
				case "BD_RACK":
					_self.title = "查询货位";
					break;
				case "ORGNAME":
					_self.title = "查询移入组织";
					break;
				case "INORGNAME":
					_self.title = "查询移出组织";
					break;
				default:
					break;
			}
			uni.setNavigationBarTitle({
				title: _self.title
			});
			_self.requestList("", _self.i);
			// console.log('App onLoad')
		},
		onShow: function() {},
		methods: {
			// ...mapMutations(['selectReduce']), // 引入 store 中的reduce方法
			inputKey: function(e) {
				let val = e.detail.value;
				if (val.length > 1) {
					this.requestList(val);
				}
			},
			handleSearch() {
				_self.requestList(_self.keyword);
				// console.log(_self.keyword);
			},
			selectData(e) {
				uni.navigateBack({});
				setTimeout(() => {
					uni.$emit("getSelectItemPro", {
						...e
					});
				}, 500)
			},
			requestList(keyword) {
				let URL = "/api/APPExtend/GetMaterials"
				let query = {
					Name: keyword,
					account: _self.userInfo.Account
				}
				// console.log(query);
				this.axios({
						url: URL,
						data: query,
						isLoading: 1
					})
					.then((res) => {
						console.log(res);
						_self.listData = res.Result;
					})
			}

		}
	};
</script>

<style scoped>
	.search-wrapper {}

	.search-list {
		background-color: #ffffff;
		margin-top: 20upx;
	}

	.list-item {
		padding: 20upx;
		border-bottom: 1px solid #dbdbdb;
		display: flex;
		justify-content: space-between;
	}

	.list-item:active {
		background-color: #ededed;
	}
</style>
